<?php

require_once 'common/conn.php';

$usercode = $_GET['usercode'];
if (!isset($usercode)) {
    $usercode = $_POST['usercode'];
}

$year = date("Y");
$month = date("n");
$db = new DBC();
$sql = "SELECT age FROM t_device WHERE devicecode = '" . $usercode . "'";
$data = $db->fetchData($sql);
$result = array();
if (count($data) > 0) {
    $age = $data[0]['age'];
    $pack = "(SELECT packcode FROM t_pack WHERE age = " . $age . " AND year = " . $year . " AND month = " . $month . ")";
    $sql = "SELECT monthcode pack1, pack2, pack3, pack4, pack5, thinking, art, language, cognition, habit FROM t_product_score_setting WHERE pack1 IN " . $pack . " OR pack2 IN " . $pack . " OR pack3 IN " . $pack . " OR pack4 IN " . $pack . " OR pack5 IN " . $pack;

    $sql = "SELECT monthcode,year,month," . $age . " AS age, thinking, art, language, cognition, habit FROM t_product_score_setting LIMIT 0,1";
    $data = $db->fetchData($sql);
    $result['data'] = $data;
}
echo json_encode($result);
?>
